package com.jn.algorithm.day010.question29;

/**
 * @author 江南大学1033190417
 * @date 2022/4/25 20:17
 */
public class Solution {

    public int divide(int dividend, int divisor) {
        long a = Math.abs((long) dividend);
        long b = Math.abs((long) divisor);
        //求取正负
        boolean f1 = a == dividend;
        boolean f2 = b == divisor;
        long count = 0;
        while (a >= 0) {
            a -= b;
            if (a >= 0) {
                ++count;
            }
        }
        if (count >= Integer.MAX_VALUE || count <= Integer.MIN_VALUE) {
            return f1 == f2 ? Integer.MAX_VALUE : Integer.MIN_VALUE;
        }
        return (int) (f1 == f2 ? count : -count);
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.divide(-2147483648, -1));
    }
}
